<?php

/*
 * litchicms
 * Copyright (C) ${date} Author: tiefa(539247@qq.com)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
!defined('BRK') && exit("!");

!empty($_SESSION['brk_login']) && header301('index.php?site-admin');


$can_action = array('from', 'login');

if (empty($_POST['action']) || !in_array($_POST['action'], $can_action)) {
    $_POST['action'] = 'show';
}

switch ($_POST['action']) {
    case 'from':


        break;
    case 'login':
        //verifycode  user_login user_pass
        if (empty($_POST['user_login'])) {
            eMsg(0, "用户名不可以为空");
            $_POST['action'] = 'error';
            break;
        }
        if (empty($_POST['user_pass'])) {
            eMsg(0, "密码不可以为空");
            $_POST['action'] = 'error';
            break;
        }
        if (empty($_SESSION['brk_verifycode']) || empty($_POST['verifycode']) || ($_POST['verifycode'] != $_SESSION['brk_verifycode'])) {
            eMsg(0, "验证码错误");
            $_POST['action'] = 'error';
            break;
        }

        if (brk_login($_POST['user_login'], sha1($_POST['user_pass']))) {
            require_rigths();
            check_rights_by_id(1);
            eMsg(1, "登陆成功, " . ($BRK_USER['user_nicename'] ? $BRK_USER['user_nicename'] : $BRK_USER['user_login']) . " 欢迎您回来!");
            eMsg(1, ($BRK_USER['user_lastlogintime'] ? "&nbsp;&nbsp;上次登录是 " . $BRK_USER['user_lastlogintime'] . " " : " ") . ($BRK_USER['user_lastloginip'] ? "&nbsp;&nbsp;IP:" . $BRK_USER['user_lastloginip'] . " " : " ") . "本次IP:" . $GLOBALS['BRK_GLOBAL']['ip'], array(0, "index.php?site-admin"));
            break;
        } else {
            eMsg(0, "用户名不存在或者密码错误!");
            $_POST['action'] = 'error';
            break;
        }
        break;
    default:
        break;
}
?>